package com.javaoop.couese;

/**
 * 课程：JavaOOP ，山西应用科技学院信息工程学院计算机科学与技术专业 2201班
 *
 * @author by 2022010101张三
 * @user Administrator
 * @Date 2024/12/7 10:01
 * @Description 任务或用途 TODO: 定义类圆继承类点
 */
public class Circle extends Point{
    private int r;

    public Circle(int x, int y, char c, int r) {
        super(x, y, c);
        this.r = r;
    }
    public Circle(Point p,char c, int r) {
        super(p.getY(), p.getY(), c);
        this.r = r;
    }
    public int getR() {
        return r;
    }

    public void setR(int r) {
        this.r = r;
    }

    public void setCircle(int r,Point p){
        this.r=r;
        setPoint(p.getX(),p.getY(),p.getC());
    }

    @Override
    public void draw(Canvas cv) {
        int h=cv.getH();
        int w=cv.getW();
        char[][] m=cv.getMatrix();
        int x,y;
        for (int i = 0; i <h; i++) {
            y=Math.abs(i-super.getY());
            for (int j = 0; j <w; j++) {
                x=Math.abs(j-super.getX());
                if(x*x+y*y<this.r*this.r){
                    m[i][j]=super.getC();
                }
            }
        }
    }

    public static void main(String[] args) {
        System.out.println("========= 继承点的圆 ========");
        Canvas cv=new Canvas(20,30,'.');
        Circle c=new Circle(15,10,'z',8);
        c.draw(cv);
//        cv.view();
        Point p=new Point(6,6,'x');
        p.draw(cv);
        c=new  Circle(p,'+',5);
        c.draw(cv);
        cv.view();
    }
}
